<%@ page language="java" import="java.util.*" import="java.sql.*,com.login.db.DbTools" pageEncoding="UTF-8"%>
<%@ page errorPage="error.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'showstu.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <%
    request.setCharacterEncoding("utf-8");
  	String username=request.getParameter("username");
  	String password=request.getParameter("password");
  	String sql = "select * from user_table where name='"+username+"' and pass='"+password+"'";
	DbTools db = new DbTools();
	ResultSet rs = db.query(sql);
	try{
		if(rs.next()){
  		session.setAttribute("username", username);
  		response.sendRedirect("welcome.jsp");
        }else{
            out.println("<script>");
            out.println("alert('用户名密码错误')");
            out.println("window.location='login.jsp'");
            out.println("</script>");
            
            //response.sendRedirect("login.jsp");   //写出的javascript代码还未执行就跳转
        }
  	}catch(Exception e){
		e.printStackTrace();
	}finally{
		db.close();
	}
   %>
   <body>
		this is Login_service
  </body>
</html>
